#!/bin/sh

if [ $# -ne 0 ]; then
	echo "Usage: this is a empty shell."
	exit
fi

cd ~/workshop/gitee/3place

if [ $# -eq 0 ]; then 
	t_date=`da +0`
	t_date_1=`daa +0`
else

	t_date=`da $1`
	t_date_1=`daa $1`
fi

t_today=`echo $t_date |sed -e "s/.*年//"`

t_date_1=`echo $t_date_1 | sed -e "s/.*年//"`

quickviewfile='quickview'

# 列出今天阅读的内容，并且生成一个单独的页面 https://blog.3plae.cn/index_quickview.html

find ~/workshop/gitee/3place | grep md | grep $t_today |sed "/年/d" >/tmp/quickview
find ~/workshop/gitee/3place | grep md | grep $t_today |grep "2024" >>/tmp/quickview


echo "% 今日快览@第三同读" > $quickviewfile.md


echo "% hbaolong@vip.qq.com">>$quickviewfile.md

echo "" >>$quickviewfile.md 

commcode header >>$quickviewfile.md

for files in `sort /tmp/quickview`
do

	filename=`echo $files | awk -F/ '{print $NF}'`

	configfile=`echo $files |awk -F $filename  '{print $1}'`

	if [ ! -e $configfile/config ]; then
		continue
	fi

	source $configfile/config

	linkindex=`echo $files |awk -F $tag '{print $2}' |awk -F_ '{print $1}'`

	burl="[阅读计划]($url)    [原文链接]($url/$tag$linkindex.html)"

# 生成每日文件，增加了折叠功能。

	echo "<details>"  >> $quickviewfile.md

	echo "<summary>" $bookname "" $burl "\n</summary>"| sed -e "s/EN//" >> $quickviewfile.md

	sed -e "/audio/d" $files  |sed -e "/^% /d" |head -8 >> $quickviewfile.md

	echo "</details>" >> $quickviewfile.md

#	echo "\n# " $bookname "\n"| sed -e "s/EN//" >> dict-$t_date.md

#	getmingju $files | sed -e "s/\[/\[<span style=\"color:green;\">小宝说：<\/span>/g">/tmp/mingju

#	echo $bookname |grep "EN$" >/dev/null

#	if [ $? -eq 0 ]; then 
#
#		while IFS= read -r line; 
#		do
#			if echo $line | grep -q " "; then 
#				echo "#### 名句\n" >> dict-$t_date.md
#				echo $line >> dict-$t_date.md
#			else
#				echo "#### " $line "\n" >> dict-$t_date.md
#				yd "\"$line\"" 2>/dev/null |  sed -e "s/.*1G//" | awk '/^[^\t]/ {print }'  | awk '{printf "> ";print ;print ""}' >> dict-$t_date.md 
#			fi
#
#		done < /tmp/mingju
#
#	else
#
#		awk '{
#		        printf ("#### %02d.\n\n" , NR);
#		        print $0 "\n";
#
#		}'  /tmp/mingju >> dict-$t_date.md
#
#	fi
done

commcode footer >> $quickviewfile.md


# 生成网页，并且同步到github.io

# pandoc -s dict-$t_date.md  -o ~/workshop/hbaolong.github.io/quickview/"dict-"$t_date.html
pandoc -s $quickviewfile.md  -o ~/workshop/hbaolong.github.io/index_quickview.html
